/**
 * 私有路由表（有权限的路由，取决于用户的权限）
 */

import { notEmpty } from '~/utils/common.js'
import { customPrivateRoutes } from '@/router/custom_private_routes'
import Placeholder from '~/views/layout/components/Placeholder/index.vue'

export const privateRoutes = [
  ...customPrivateRoutes,
  {
    path: '/test-private',
    name: 'testPrivate',
    component: Placeholder
  }
]

/**
 * 遍历提取privateRoutes中的路由name，形成列表
 */
export const privateRouteNames = (() => {
  function travelRouteTree(privateRouteNames, routeNode) {
    if (notEmpty(routeNode)) {
      if (routeNode.name && routeNode.name.length > 0) {
        privateRouteNames.push(routeNode.name)
      }
      if (notEmpty(routeNode.children)) {
        routeNode.children.forEach(childRoute => {
          travelRouteTree(privateRouteNames, childRoute)
        })
      }
    }
  }

  const privateRouteNames = []
  privateRoutes.forEach(rootRoute => {
    travelRouteTree(privateRouteNames, rootRoute)
  })
  return privateRouteNames
})()
